package cn.zhyjohn.paysystem.action;

import cn.zhyjohn.paysystem.biz.AlipayManager;
import cn.zhyjohn.paysystem.common.Response;
import cn.zhyjohn.paysystem.requset.AliPayParams;
import cn.zhyjohn.paysystem.requset.AliTradePayParams;
import cn.zhyjohn.paysystem.requset.AliTradePrecreateParams;
import cn.zhyjohn.paysystem.requset.AliTradeRefundParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;

/**
 * @author JOHN
 * @title: AliPayController
 * @projectName paysystem
 * @since 2019/8/27
 */
@RestController
@RequestMapping(value = "pay")
@Api(tags = "支付宝支付接口")
public class AliPayController {

    @Autowired
    private AlipayManager alipayManager;

    /**
     * 支付宝app支付
     * @author JOHN
     * @param params
     * @date 11:43
     **/
    @PostMapping(value = "/alipay/appPay")
    @ApiOperation(value = "支付宝-app支付")
    public Response appPay(@Valid AliPayParams params) {
        return alipayManager.appPay(params);
    }

    /**
     * 支付宝Wap支付
     * @author JOHN
     * @date 11:46
     * @param params
     **/
    @PostMapping(value = "/alipay/wapPay")
    @ApiOperation(value = "支付宝-Wap支付")
    public Response wapPay(HttpServletResponse response, @Valid AliPayParams params) {
        return alipayManager.wapPay(response, params);
    }

    /**
     * 支付宝PC支付
     * @author JOHN
     * @date 11:53
     * @param params
     **/
//    @PostMapping(value = "/alipay/pcPay")
    @GetMapping(value = "/alipay/pcPay")
    @ApiOperation(value = "支付宝-PC支付")
    public Response pcPay(HttpServletResponse response, @Valid AliPayParams params) {
        return alipayManager.pcPay(response, params);
    }

    /**
     * 支付宝条码/声波支付
     * @author JOHN
     * @date 11:59
     * @param params
     **/
    @PostMapping(value = "/alipay/tradePay")
    @ApiOperation(value = "支付宝-条码/声波支付")
    public Response tradePay(@Valid AliTradePayParams params) {
        return alipayManager.tradePay(params);
    }

    /**
     * 支付宝扫码支付
     * @author JOHN
     * @date 12:03
     * @param precreatePay
     **/
    @GetMapping(value = "/alipay/tradePrecreatePay")
    @ApiOperation(value = "支付宝-扫码支付", produces="image/png")
    public Response tradePrecreatePay(HttpServletResponse response, @Valid AliTradePrecreateParams precreatePay) throws IOException {
        return alipayManager.tradePrecreatePay(response, precreatePay);
    }

    /**
     * 支付宝单笔转账到支付宝账户
     * @author JOHN
     * @date 13:39
     * @param params
     **/
    @PostMapping(value = "/alipay/transfer")
    @ApiOperation(value = "支付宝-提现")
    public Response transfer(@Valid AliPayParams params) {
        return alipayManager.transfer(params);
    }

    /**
     * 支付宝退款
     * @author JOHN
     * @date 13:49
     * @param params
     **/
    @PostMapping(value = "/alipay/tradeRefund")
    @ApiOperation(value = "支付宝-退款")
    public Response tradeRefund(@Valid AliTradeRefundParams params) {
        return alipayManager.tradeRefund(params);
    }
}
